publicstaticvoidsolve() { intn= io.nextInt(), x = io.nextInt(); intmin=101, max = -1, sum = 0; for (inti=0; i < n - 1; i++) { intt= io.nextInt(); sum += t; min = Math.min(min, t); max = Math.max(max, t); } intt= x - (sum - min - max); if (t > max) { io.println(-1); } else { io.println(t <= min ? 0 : t); } }
publicstaticvoidsolve() { intn= io.nextInt(), m = io.nextInt(), p = io.nextInt(); int[] a = newint[n]; for (inti=0; i < n; i++) { a[i] = io.nextInt(); } int[] b = newint[m]; for (inti=0; i < m; i++) { b[i] = io.nextInt(); } Arrays.sort(b); long[] sum = newlong[m + 1]; for (inti=0; i < m; i++) { sum[i + 1] = sum[i] + b[i]; } longans=0L; for (inti=0; i < n; i++) { intx= p - a[i]; intlo=0, hi = m - 1; while (lo <= hi) { int mid= lo + (hi - lo) / 2; if (b[mid] <= x) lo = mid + 1; else hi = mid - 1; } ans += ((long) lo * a[i] + sum[lo]) + (long) (m - lo) * p; } io.println(ans); }